<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!--返回错误信息-->
<?php echo validation_errors(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php
    $title = [
        'title' => '统计分析管理/出入库统计/商品出入库统计',
    ];
    $this->load->view('/admin/common/header', $title);
    ?>
</head>

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    <!--    头部   侧边菜单-->
    <?php $this->load->view('/admin/common/bodyLeft'); ?>
    <script type="text/javascript">
        $(".js-sidebar-nav>li:nth-child(11)>ul, .js-sidebar-nav>li:nth-child(11)>ul>li:nth-child(3)>ul").show(80);
        $(".js-sidebar-nav>li:nth-child(11)>a>span, .js-sidebar-nav>li:nth-child(11)>ul>li:nth-child(3)>a>span").addClass("sidebar-nav-sub-ico-rotate");
        $(".js-sidebar-nav>li:nth-child(11)>ul>li:nth-child(3)>a ,.js-sidebar-nav>li:nth-child(11)>ul>li:nth-child(3)>ul>li:nth-child(1)>a").addClass("active");
    </script>
    <!-- 内容区域 -->
    <div class="tpl-content-wrapper statement">

        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">商品出入库统计</div>
                        </div>
                        <div class="widget-body  am-fr">
                            <div class="am-u-sm-6 am-u-md-6 am-u-lg-6">
                                <div class="am-btn-toolbar">
                                    <div class="am-g">
                                        <div class="am-u-sm-12 am-u-md-6 am-form-group">
                                            <button type="button" class="am-btn am-btn-default am-margin-right"
                                                    id="my-start">开始日期
                                            </button>
                                            <span id="my-startDate"></span>
                                        </div>
                                        <div class="am-u-sm-12 am-u-md-6 am-form-group">
                                            <button type="button" class="am-btn am-btn-default am-margin-right"
                                                    id="my-end">结束日期
                                            </button>
                                            <span id="my-endDate"></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-6 am-u-md-6 am-u-lg-6">

<!--                                <div class="am-u-sm-12 am-u-md-12 am-u-lg-6">-->
<!--                                    <div class="am-form-group am-input-group am-input-group-sm tpl-form-border-form cl-p">-->
<!--                                        <!--                                    <form action="/admin/user/search" method="get">-->
<!--                                        <input type="text" class="am-form-field" name="search" id="search">-->
<!--                                        <span class="am-input-group-btn">-->
<!--                                            <a href="javascript:void(0)" onclick="search123()"-->
<!--                                               class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search">搜索</a>-->
<!--                                        </span>-->
<!--                                        <!--                                    </form>-->
<!--                                    </div>-->
<!--                                </div>-->

                            </div>
                            <div class="am-u-sm-12 am-form-group ">
                                <div class="am-btn-toolbar am-u-sm-12">
                                    <div class=" am-btn-group-xs">
                                        <?php
                                        $type = isset($_GET['type']) ? $_GET['type'] : 'put';
                                        ?>
                                        <a href="javascript:void(0);" onclick="put()"
                                           class="am-btn   <?php if ($type == 'put') {
                                               echo 'am-btn-primary';
                                           } else {
                                               echo 'am-btn-default';
                                           } ?> ">商品入库</a>
                                        <a href="javascript:void(0);" onclick="out()"
                                           class="am-btn  <?php if ($type == 'out') {
                                               echo 'am-btn-primary ';
                                           } else {
                                               echo 'am-btn-default';
                                           } ?> ">商品出库</a>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-form-group ">
                                <div class="am-btn-toolbar am-u-sm-12">
                                    <div class=" am-btn-group-xs">
                                        <a href="javascript:void(0);" onclick="" class="am-btn am-btn-primary"><span
                                                    class="am-icon-download"></span> 导出</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="am-u-sm-12">
                            <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black "
                                   id="example-r">
                                <thead>
                            <?php
                                if(isset($putlist) && $putlist){
                                    echo '<tr>
                                <td>序号</td>
                                <td>商品编码</td>
                                <td>商品名称</td>
                                <td>商品来源</td>
                                <td>所属供应商</td>
                                <td>商品分类</td>
                                <td>入库数量</td>
                                <td>入库金额</td>
                            </tr>';
                                }else if(isset($outlist) && $outlist){
                                    echo '<tr>
                                <td>序号</td>
                                <td>商品编码</td>
                                <td>商品名称</td>
                                <td>商品来源</td>
                                <td>所属供应商</td>
                                <td>商品分类</td>
                                <td>出库数量</td>
                                <td>出库金额</td>
                            </tr>';
                                }
                            ?>
                                </thead>

                                <tbody class="choose-box">
                            <?php
                            if (isset($putlist) && $putlist) {
                                //2物料包、3书籍、4机器耗材、9打印机租赁、8供应商商品
                                foreach ($putlist as $v) {
                                    $dataId = $v['ckId'] ? $v['ckId'] : $v['id'];

                                    echo '<tr>';
                                    echo'<td date-id="' . $dataId . '">' . $v['id'] . '</td>';
                                    if(substr($v['product_no'],0,3) == 'ist'){
                                        echo '<td><a href="/admin/statement/outAndPutByGoodsPutDetails?goodsId='.$v['id'].'">' . $v['product_no'] . '</a></td>';
                                    }else{
                                        echo '<td>' . $v['product_no'] . '</td>';
                                    }

                                      echo '<td>' . $v['name'] . '</td>';
                                    if($v['source'] == 'ist'){
                                        echo '<td>爱思特</td>';
                                    }elseif ($v['source'] == '51ck'){
                                        echo '<td>51ck平台</td>';
                                    }

                                    echo '<td>'.$v['supplier'].'</td>';

                                    switch ($v['one_category']){
                                        case 2:
                                            echo '<td>物料包</td>';
                                            break;
                                        case 3:
                                            echo '<td>书籍</td>';
                                            break;
                                        case 4:
                                            echo '<td>机器耗材</td>';
                                            break;
                                        case 8:
                                            echo '<td>供应商商品</td>';
                                            break;
                                        case 9:
                                            echo '<td>打印机租赁</td>';
                                            break;
                                    }
                                    echo '<td>' . $v['quantity'] . '</td><td>' . $v['priceAll'] . '</td>';


                                    echo    '</tr>';
                                }
                            }else if(isset($outlist) && $outlist){
                                foreach ($outlist as $v2) {
                                    $dataId = $v2['ckId'] ? $v2['ckId'] : $v2['id'];

                                    echo '<tr>';
                                    echo'<td date-id="' . $dataId . '">' . $v2['id'] . '</td>';
                                    if(substr($v2['product_no'],0,3) == 'ist'){
                                        echo '<td><a href="/admin/statement/outAndPutByGoodsOutDetails?goodsId='.$v2['id'].'">' . $v2['product_no'] . '</a></td>';
                                    }else{
                                        echo '<td>' . $v2['product_no'] . '</td>';
                                    }

                                    echo '<td>' . $v2['name'] . '</td>';
                                    if($v2['source'] == 'ist'){
                                        echo '<td>爱思特</td>';
                                    }elseif ($v2['source'] == '51ck'){
                                        echo '<td>51ck平台</td>';
                                    }

                                    echo '<td>'.$v2['supplier'].'</td>';

                                    switch ($v2['one_category']){
                                        case 2:
                                            echo '<td>物料包</td>';
                                            break;
                                        case 3:
                                            echo '<td>书籍</td>';
                                            break;
                                        case 4:
                                            echo '<td>机器耗材</td>';
                                            break;
                                        case 8:
                                            echo '<td>供应商商品</td>';
                                            break;
                                        case 9:
                                            echo '<td>打印机租赁</td>';
                                            break;
                                    }
                                    echo '<td>' . $v2['quantity'] . '</td><td>' . $v2['quantity'] . '</td>';


                                    echo    '</tr>';
                                }
                            }
                            ?>
                                </tbody>
                            </table>
                        </div>
                        <div class="am-u-lg-12">
                            <div class="am-u-sm-centered">
                                <ul class="am-pagination am-pagination-centered" id="paging">

                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 模态框 -->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="addSpecification">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">规格值详情
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            <table class="am-table am-table-bordered am-table-radius am-table-striped am-table-hover">
                <thead>
                <tr>
                    <th style="width: 50%">规格值</th>
                    <th style="width: 50%">单品编码</th>
                </tr>
                </thead>
                <tbody class="specification-box">

                </tbody>
            </table>
        </div>
        <div class="btn-box">
            <button type="button" class="am-btn am-btn-primary" id="confirmSpecification" data-am-modal-close>确认
            </button>
        </div>

    </div>
</div>
<script src="/assets/js/amazeui.min.js"></script>
<script src="/assets/js/amazeui.datatables.min.js"></script>
<script src="/assets/js/dataTables.responsive.min.js"></script>
<script src="/assets/js/app.js"></script>
<script src="/assets/js/page.js"></script>
<script>
    $(function () {

        //点击规格显示规格列表
        var unlock = false;
        $(document).on("click", ".guige", function () {
            if (unlock) {
                return false;
            }

            var guigeBox = $(this).siblings(".guige-box");
            var hasGuige = $(this).parent(".guige-ul").siblings(".guige-ul");
            var guigeLen = hasGuige.length;

            unlock = true;
            $(guigeBox).slideToggle(function () {
                unlock = false;
            });

            for (var i = 0; i < guigeLen; i++) {
                if (hasGuige.eq(i).children(".guige-box").css("display") != 'none') {
                    hasGuige.eq(i).children(".guige-box").slideToggle();
                }
            }

        });


        $(document).on("click", ".specification-btn", function () {
            var thisTr = $(this).parents(".gradeX");                        //点击的本行tr
            var productId = thisTr.children("td:first-child").data("id");   //传给后台的商品ID
            console.log(productId)

            var specificationBox = $(".specification-box");

//        specificationBox.empty();
            $.ajax({
                url: "/api/goods/getGoodsIdByData",
                data: {
                    productId: productId
                },
                dataType: "json",
                type: "post",
                success: function (data) {
//                console.log(data);
                    var tr = "";
                    for (var i = 0; i < data.length; i++) {
                        tr += '<tr>'
                            + '<td>' + data[i].specification_group_names + '</td>'
                            + '<td>' + data[i].group_no + '</td>'
                            + '</tr>';
                    }

                    specificationBox.html(tr);
                },
                error: function (data) {
                    console.log(data);
                }
            });
        });

        var startDate = new Date(2014, 11, 20);
        var endDate = new Date(2014, 11, 25);
        var $alert = $('#my-alert');
        $('#my-start').datepicker().on('changeDate.datepicker.amui', function (event) {
            if (event.date.valueOf() > endDate.valueOf()) {
                $alert.find('p').text('开始日期应小于结束日期！').end().show();
            } else {
                $alert.hide();
                startDate = new Date(event.date);
                $('#my-startDate').text($('#my-start').data('date'));
            }
            $(this).datepicker('close');
        });

        $('#my-end').datepicker().on('changeDate.datepicker.amui', function (event) {
            if (event.date.valueOf() < startDate.valueOf()) {
                $alert.find('p').text('结束日期应大于开始日期！').end().show();
            } else {
                $alert.hide();
                endDate = new Date(event.date);
                $('#my-endDate').text($('#my-end').data('date'));
            }
            $(this).datepicker('close');
        });
    });
</script>

<script>
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)return unescape(r[2]);
        return null;
    }
    function put() {
        var search = GetQueryString('search');
        // $(".am-btn-primary").removeClass("am-btn-primary");
        // $(this).addClass("am-btn-primary");

        if (search == null) {
            window.location.href = '?page=1' + '&type=put'
        } else {
            window.location.href = '?page=1' + '&search=' + search + '&type=put'
        }
    }
    function out() {
        var search = GetQueryString('search');
        if (search == null) {
            window.location.href = '?page=1' + '&type=out'
        } else {
            window.location.href = '?page=1' + '&search=' + search + '&type=out'

        }
    }
   </script>

</body>

</html>